package top.honlnk.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import top.honlnk.pojo.entity.RotaSecretKey;
import top.honlnk.pojo.entity.SchoolTimetable;

import java.util.List;

@Mapper
public interface AdminMapper {
    // 向rota_secret_key插入一条新数据
    @Insert("INSERT INTO rota_secret_key(admin_key, time) VALUES (#{adminKey}, #{time})")
    void insert(RotaSecretKey rotaSecretKey);
    // 更新rota_secret_key，根据admit_key更新rota字段
    @Insert("UPDATE rota_secret_key SET rota = #{rota} WHERE admin_key = #{adminKey}")
    void updateRota(String rota, String adminKey);
    // 获取rota_secret_key表中admin_key为key的数据
    @Select("SELECT * FROM rota_secret_key WHERE admin_key = #{key}")
    RotaSecretKey getRotaSecretKey(String key);
    // 获取school_timetable表中key_id为id的数据
    @Select("SELECT name, `table` FROM school_timetable WHERE key_id = #{keyId}")
    List<SchoolTimetable> getSchoolTimetableList(int keyId);
    // 根据rota_secret_key表中的admin_key查询school_timetable表中的信息。
    @Select("SELECT s.name, s.`table`, s.submit_id FROM school_timetable AS s WHERE s.key_id = (SELECT r.id FROM rota_secret_key AS r WHERE r.admin_key = #{key})")
    List<SchoolTimetable> getUserTable(String key);

    @Delete("DELETE FROM school_timetable WHERE submit_id = #{submitId}")
    void deleteSchoolTimetable(String submitId);
}
